<?php 
require "DataLoad.php";
CheckAdmin2();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<?php 
$STi=$Timer;
?>

<html>
<head>
<title><?php echo $GuildName;?> - DKP系统</title>
<script language="JavaScript" src="inc/jquery.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="Generator" content="EditPlus">
<meta name="Author" content="SULei">
<meta name="Keywords" content="DKP WOW GUILD">
<meta name="Description" content="">
<link href="<?php echo $StylePath;?>/main.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" src="<?php echo $StylePath;?>/styleplus.js"></script>
<style type="text/css" media="all">

</style>


</head>

<body>

<?php 
if (CheckAdmin()==false) {

	header("Location: "."dkplist_".${"class"}.".html");
	exit();

} 

?>
<div class="header">
<?php
require "menu.php";
?>
</div>
<div class="main">
			<?php 
dkplist(${"class"});

?>
</div>
<?php require "footer.php"; ?>
</body>
</html>
<?php 
function dkplist($cid) {
	extract($GLOBALS);



	$NumberCount=0;
	$profession="";
	$raidth="";

	switch ($_POST["filter"]) {
		case "Warrior":
			$sqlw="player_class='战士' ";
			break;
		case "Mage":
			$sqlw="player_class='法师' ";
			break;
		case "Priest":
			$sqlw="player_class='牧师' ";
			break;
		case "Rogue":
			$sqlw="player_class='盗贼' ";
			break;
		case "Hunter":
			$sqlw="player_class='猎人' ";
			break;
		case "Druid":
			$sqlw="player_class='德鲁伊' ";
			break;
		case "Warlock":
			$sqlw="player_class='术士' ";
			break;
		case "Paladin":
			$sqlw="player_class='圣骑士' ";
			break;
		case "Shaman":
			$sqlw="player_class='萨满'";
			break;
		default:

			$sqlw="1=1";
			break;
	} 

	$sql="select id,raid_actiontime,raid_name from raid where raid_step=1 and raid_class=".$cid." order by raid_actiontime";
	$result = mysql_query($sql);
	$colcount=$result->recordcount;
	for ($i=1; $i<=$result->recordcount; $i=$i+1) {
		$raidth=$raidth."<th><a href='raid_report.php?id=".$result["id"]."'>".time_type($result["raid_actiontime"],1)."<br>".substr($result["raid_name"],0,7)."</a></th>"."\r\n";
		$listArr[$i-1]=$result["id"];
		$result->movenext;

	}

	$raidth=$raidth."<th>S</th><th>总计</th>";
	$result->close;
	$raidth=$raidth."</tr>";




//==================
	$sql="select id,player_class,player_name,player_Basedkp from player where ".$sqlw." and player_lastraid > #".$DateADD["d"][$freezeday][$today]."# order by player_class desc , player_name";
//打开会员表
	$result = mysql_query($sql);

//遍历会员表
	for ($z=1; $z<=$result->recordcount; $z=$z+1) {
		$chkNum=0;
		$SpecDKP=0;
		$raidtd="";
		if ($profession!=$result["player_class"]) {

			$profession=$result["player_class"];
			$raidtr=$raidtr."<tr class='spaceline'><td colspan='".(count($listArr)+5)."'>".ProPic($result["player_class"]).$result["player_class"]."</td></tr>"."\r\n";
		} 

		$dkptotal=0;
		$raidtd=$raidtd."	<tr>";
		$raidtd=$raidtd."<td><a href='player_detail.php?id=".$result["id"]."'>".$result["player_name"]."</a></td>";
		$raidtd=$raidtd."<td>".cPre(BaseDKP($result["id"],$cid))."</td>";
		$chkNum=$chkNum+BaseDKP($result["id"],$cid);
		$BaseTotal=$BaseTotal+BaseDKP($result["id"],$cid);
		$dkptotal=$dkptotal+BaseDKP($result["id"],$cid);
		$sql="select * from dkplist where playerid=".$result["id"]; //打开DKP表
		$result = mysql_query($sql);
		if ($result2->bof || $result2->eof) {

		}
			else
		{

			for ($i=0; $i<=count($listArr); $i=$i+1) {
				for ($iy=1; $iy<=$result2->recordcount; $iy=$iy+1) {
				  if ($listArr[$i]==$result2["raidid"]) {
//匹配DKP到活动ID
				    $dkpArr[$i]=$result2["dkp"];
				    $totalArr[$i]=$totalArr[$i]+$result2["dkp"];
				    $dkptotal=$dkptotal+$result2["dkp"];
				  } 

				  $result2->movenext;

				}

				$result2->movefirst;

			}

		} 

		$FinalTotal=$FinalTotal+$dkptotal;
		$result2->close;
		for ($i=0; $i<=count($dkpArr); $i=$i+1) {
			$raidtd=$raidtd."<td ".checkdkp($dkpArr[$i]).">".cPre($dkpArr[$i])."</td>";
			if (is_numeric($dkpArr[$i])) {
				$chkNum=$chkNum+intval($dkpArr[$i])+0.113;
			} 
			$dkpArr[$i]="-";

		}



//特殊事件SpecDKP
		$sql="select event_object,event_dkp from raid_event where raid_class=".$cid." and (event_object='".$result["player_name"]."' or event_object like '%|".$result["player_name"]."|%' )";
		$result2 = mysql_query($sql);
		for ($ij=1; $ij<=$result2->recordcount; $ij=$ij+1) {
			$SpecDKP=$SpecDKP+$result2["event_dkp"];
			$result2->movenext;

		}

		$SpecTotal=$SpecTotal+$SpecDKP;
		$result2->close;

		$raidtd=$raidtd."<td>".cPre($SpecDKP)."</td>";
		$chkNum=$chkNum+$SpecDKP;
		$raidtd=$raidtd."<td>".tcolor(cPre($dkptotal+$SpecDKP))."</td>";
		$raidtd=$raidtd."</tr>"."\r\n";

playerupdate($result["id"],$result["player_name"],$cid,$dkptotal+$SpecDKP);//更新成员表DKP


		if ($chkNum!=0) {

			$raidtr=$raidtr.$raidtd; //如果未参见过此类活动就不显示
			$NumberCount=$NumberCount+1;
			$SimpleDataArr[$z-1][0]=$result["player_name"];
			$SimpleDataArr[$z-1][1]=$dkptotal+$SpecDKP;
			$SimpleDataArr[$z-1][2]=$result["player_class"];
		} 



		$result->movenext;

	}

	$result->close;
	$raidth="<tr><th>共".$NumberCount."名成员</th><th>基础</th>".$raidth;

//==================
//纵向统计
	$totaltd=$totaltd."<tr class='sth'><th>统计</th><th>".cPre($BaseTotal)."</th>";
	for ($i=0; $i<=count($totalArr); $i=$i+1) {
		$totaltd=$totaltd."<th>".cPre($totalArr[$i])."</th>";

	}

	$totaltd=$totaltd."<th>".cPre($SpecTotal)."</th><th>".cPre($FinalTotal+$SpecTotal)."</th></tr>";

//立刻显示结果
//Response.write "<table class='dkplist'>"&vbCrlf
//Response.write raidth&raidtr&raidth&totaltd&vbCrlf
//Response.write "</table>"


//Response.write join(listArr)

//生成HTML文件
	if (!($_POST["filter"]!="")) {

		$htmlhead="<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html><?php require "footer.php"; ?><body>";

		$htmlhead=$htmlhead."<div class='header'><h1>".$GuildName."<span>".getRaidClassText($cid)."分类DKP详表,更新时间:".strftime("%m/%d/%Y %H:%M:%S %p")." <a href='default.php'>返回首页</a></span></h1></div>";
		$htmlfooter="<div class='footer'><div>创建时间: ".strftime("%m/%d/%Y %H:%M:%S %p")."</div></div>";
		$strjQueryStyle="<script type=\"text/javascript\">\$(\"tr:even:not(.spaceline)\").addClass(\"b\");\$(\"tr:odd:not(.spaceline)\").addClass(\"a\");\$(\"tr\").toggle(function () {\$(this).addClass(\"scte\");},function () {\$(this).removeClass(\"scte\");});\$(\"tr:not(.spaceline)\").hover(function () {\$(this).addClass(\"ishover\");},function () {\$(this).removeClass(\"ishover\");});\$(\"li\").toggle(function () {\$(this).addClass(\"scte\");},function () {\$(this).removeClass(\"scte\");});\$(\"li\").hover(function () {\$(this).addClass(\"ishover\");},function () {\$(this).removeClass(\"ishover\");});</script>";



//普通版
		$fso=$DOCUMENT_ROOT."dkplist_".$cid.".html";
		// $f is of type "ADODB.Stream"
		$f->Open;
		$f->Charset="utf-8";
		$f->WriteText=($htmlhead."<table class='dkplist'>".$raidth.$raidtr.$raidth.$totaltd."</table>".$Htmlfooter.$strjQueryStyle."</body></html>");
		$f->SaveToFile;
		$f->Close;
		$fso=null;


//简化版
		$fso=$DOCUMENT_ROOT."dkpsimplelist_".$cid.".html";
		// $f is of type "ADODB.Stream"
		$f->Open;
		$f->Charset="utf-8";
		$f->WriteText=($htmlhead.SimpleFormat($SimpleDataArr).$Htmlfooter.$strjQueryStyle."</body></html>");
		$f->SaveToFile;
		$f->Close;
		$fso=null;


//纯文字版
		$fso=$DOCUMENT_ROOT."dkpText_".$cid.".html";
		// $f is of type "ADODB.Stream"
		$f->Open;
		$f->Charset="utf-8";
		$f->WriteText=($htmlhead."<textarea class=\"dkptext\"  cols=\"80\" rows=\"36\">".TextFormat($SimpleDataArr,$cid)."</textarea></body></html>");
		$f->SaveToFile;
		$f->Close;
		$fso=null;


//XML
		$fso=$DOCUMENT_ROOT."dkplist_".$cid.".xml";
		// $f is of type "ADODB.Stream"
		$f->Open;
		$f->Charset="utf-8";
		$f->WriteText=(XMLFormat($SimpleDataArr));
		$f->SaveToFile;
		$f->Close;
		$fso=null;


	} 



//更新分类更新日期
	mysql_query("update raid_class set closing_date='".strftime("%m/%d/%Y %H:%M:%S %p")."' where id=".$cid);

//
workcomplete($cid);

	return $function_ret;
} 

function workcomplete($cid) {
	extract($GLOBALS);

	print "<div class='message'>";
	print "<h3>更新完成</h3>";
	print "<div>";
	print "<a class='abtn' href='dkplist_".$cid.".html'>详细报表</a> <a class='abtn' href='dkpsimplelist_".$cid.".html'>简单列表</a> <a class='abtn' href='dkpText_".$cid.".html'>文本格式</a>";
	print "<br><br><br><a href='.'>返回首页</a>";
	print "</div>";
	print "</div>";
	return $function_ret;
} 

function tcolor($t) {
	extract($GLOBALS);

	if ($t>0 && $t<50) {

		$function_ret="<span class='ta'>".$t."</span>";
	}
		else
	if ($t>49 && $t<100) {

		$function_ret="<span class='taa'>".$t."</span>";
	}
		else
	if ($t>99) {

		$function_ret="<span class='taaa'>".$t."</span>";
	}
		else
	if ($t<0 && $t>-20) {

		$function_ret="<span class='tb'>".$t."</span>";
	}
		else
	if ($t<-20 && $t>-100) {

		$function_ret="<span class='tbb'>".$t."</span>";
	}
		else
	if ($t<-100) {

		$function_ret="<span class='tbbb'>".$t."</span>";
	}
		else
	{

		$function_ret=$t;
	} 

	return $function_ret;
} 

function checkdkp($dkp) {
	extract($GLOBALS);

	if ($dkp!="" && $dkp!="-") {

		$function_ret=" class='iFull' ";
	}
		else
	{

		$function_ret="";
	} 

	return $function_ret;
} 

function playerupdate($pid,$pname,$cid,$dkp) {
	extract($GLOBALS);

	$sql="select top 1 * from player_dkp where player_id=".$pid." and raid_class=".$cid;
	$result2->open;
	if ($result2->bof || $result2->eof) {

//创建新记录
		print "创建新成员DKP:".$pname."<br>";
		$conn->execute("INSERT INTO player_dkp (player_id,player_name,raid_class,player_dkp,player_Basedkp) values ('".$pid."','".$pname."',".$cid.",0,0)");
	}
		else
	{

		$conn->execute("update player_dkp set player_dkp=".$dkp." where raid_class=".$cid." and player_id=".$pid);
	} 

	$result2->close;
	return $function_ret;
} 

function selectpro() {
	extract($GLOBALS);

	$stext=$stext."<form method='post' action=''><select name='filter' onChange='javascript:submit();'>";
	$stext=$stext."<option value=''>过滤</option>";
	$stext=$stext."<option value='All'>ALL</option>";
	$stext=$stext."<option value='Warrior'>Warrior</option>";
	$stext=$stext."<option value='Priest'>Priest</option>";
	$stext=$stext."<option value='Mage'>Mage</option>";
	$stext=$stext."<option value='Paladin'>Paladin</option>";
	$stext=$stext."<option value='Hunter'>Hunter</option>";
	$stext=$stext."<option value='Warlock'>Warlock</option>";
	$stext=$stext."<option value='Druid'>Druid</option>";
	$stext=$stext."<option value='Rogue'>Rogue</option>";
	$stext=$stext."<option value='Shaman'>Shaman</option>";
	$stext=$stext."</select></form>";
	$function_ret=$stext;
	return $function_ret;
} 

function SimpleFormat($t) {
	extract($GLOBALS);

	$function_ret=$SimpleFormat+"<ul class='simplelist'>";
	for ($iig=0; $iig<=count($t); $iig=$iig+1) {
		if ($t[$iig][0]!="") {

			$function_ret=$SimpleFormat+"<li><span>".cPre($t[$iig][1])."</span>".ProPic($t[$iig][2]).$t[$iig][0]."</li>";
		} 


	}

	$function_ret=$SimpleFormat+"</ul>";
	return $function_ret;
} 

function XMLFormat($t) {
	extract($GLOBALS);

	$function_ret=$XMLFormat+"<?xml version=\"1.0\" encoding=\"UTF-8\"?><dkplist>";
	for ($iig=0; $iig<=count($t); $iig=$iig+1) {
		if ($t[$iig][0]!="") {

			$function_ret=$XMLFormat+"<dkp name=\"".$t[$iig][0]."\" dkp=\"".cPre($t[$iig][1])."\" />";
		} 


	}

	$function_ret=$XMLFormat+"</dkplist>";
	return $function_ret;
} 


function TextFormat($t,$cid) {
	extract($GLOBALS);

	$function_ret=$TextFormat+$GuildName."公会 ".getRaidClassText($cid)."DKP统计表 更新于:".strftime("%m/%d/%Y %H:%M:%S %p")."\r\n";
	$function_ret=$TextFormat+"-------------------------------------------------------------"."\r\n";
	for ($iig=0; $iig<=count($t); $iig=$iig+1) {
		if ($t[$iig][0]!="") {

			$function_ret=$TextFormat+Balm($t[$iig][2],10).Balm($t[$iig][0],24).cPre($t[$iig][1])."\r\n";
		} 


	}

	$function_ret=$TextFormat+"-------------------------------------------------------------"."\r\n";
	$function_ret=$TextFormat+"完成　　".strftime("%m/%d/%Y %H:%M:%S %p")." 　由FSDKP系统生成"."\r\n";
	return $function_ret;
} 

function Balm($txt,$tlong) {
	extract($GLOBALS);
//排版补白 文字,需要长度
	//$function_ret=$txt.str_repeat("　",abs($tlong-intval(len2($txt)))*0->5);		???
	return $function_ret;
} 




//$ETi=$Timer[];

?>
